# main.py
"""
Author: didiplus
Description: 应用主入口
Date: 2025-08-20 22:38:23
LastEditors: didiplus
LastEditTime: 2025-08-20 22:38:24
FilePath: /WeChatBot/app/main.py
Version: 1.0
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
# 使用绝对导入方式引入模块
from core import init_db
from core.settings import settings
from api import api_router

# 初始化数据库
init_db()

# 创建FastAPI应用
app = FastAPI(
    title=settings.APP_TITLE,
    description=settings.APP_DESCRIPTION,
    version="1.0.0",
)

# 添加CORS中间件
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册API路由
app.include_router(api_router, prefix="/api/v1")

@app.get("/")
async def root():
    """
    根路径
    """
    return {"message": "欢迎使用关键词匹配系统"}

@app.get("/health")
async def health_check():
    """
    健康检查
    """
    return {"status": "healthy"}

if __name__ == "__main__":
    uvicorn.run(
        "main:app",
        host="0.0.0.0",
        port=8000,
        reload=True
    )